package com.ylsk.statistics.controller;

import com.ylsk.check.domain.so.CheckRecordSO;
import com.ylsk.check.domain.so.ReportInfoSO;
import com.ylsk.check.domain.vo.WithdrawalReportVO;
import com.ylsk.common.core.controller.BaseController;
import com.ylsk.common.core.domain.AjaxResult;
import com.ylsk.common.core.page.TableDataInfo;
import com.ylsk.common.utils.poi.ExcelUtil;
import com.ylsk.statistics.domain.vo.CheckCountTotalVO;
import com.ylsk.statistics.domain.vo.ProjectProcessTotalVO;
import com.ylsk.statistics.service.ReportFormsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statistics/reportForms/")
public class ReportFormsController extends BaseController {

    @Autowired
    private ReportFormsService reportFormsService;

    /**
     * 查询报备信息各个时间节点信息
     */
    @GetMapping("selectProjectTimeNodeInfo")
    public AjaxResult selectProjectTimeNodeInfo(Long reportInfoId)
    {
        List<Map<String,Object>> list = reportFormsService.getProjectTimeNodeInfo(reportInfoId);
        for (Map<String, Object> map : list) {
            String nodeName = String.valueOf(map.get("node_name"));
            buildJump(nodeName,map);
        }
        return AjaxResult.success(list);
    }

    /**
     * 项目报备统计
     */
    @GetMapping("selectProjectReportTotal")
    public AjaxResult selectProjectReportTotal()
    {
        List projectReportTotal = reportFormsService.getProjectApprStatusTotal();
        return AjaxResult.success(projectReportTotal);
    }

    private void buildJump(String nodeName,Map<String,Object> map){
        String jump = "";
        if(nodeName.equals("项目报备")){
            jump= "/project/reportInfo";
        }else if(nodeName.equals("进场上报")){
            jump = "/project/entryReport";
        }else if(nodeName.equals("占到报备")){
            jump = "/project/jeevesReport";
        }else if(nodeName.equals("撤场上报")){
            jump = "/project/withdrawalReport";
        }
        map.put("jump",jump);
    }

    /**
     * 项目过程统计
     */
    @GetMapping("selectProjectProcessTotal")
    public TableDataInfo selectProjectProcessTotal(ReportInfoSO reportInfoSO)
    {
        startPage();
        List<ProjectProcessTotalVO> list = reportFormsService.getProjectProcessTotal(reportInfoSO);
        return getDataTable(list);
    }

    /**
     * 导出项目过程统计信息列表
     */
    @PostMapping("/exportProjectProcessTotal")
    public void exportProjectProcessTotal(HttpServletResponse response, ReportInfoSO reportInfoSO)
    {
        List<ProjectProcessTotalVO> list = reportFormsService.getProjectProcessTotal(reportInfoSO);
        ExcelUtil<ProjectProcessTotalVO> util = new ExcelUtil<ProjectProcessTotalVO>(ProjectProcessTotalVO.class);
        util.exportExcel(response, list, "施工过程统计数据");
    }


    /**
     * 施工检查数量统计
     */
    @GetMapping("selectCheckCountTotal")
    public TableDataInfo selectCheckCountTotal(CheckRecordSO checkRecordSO)
    {
        startPage();
        List<CheckCountTotalVO> list = reportFormsService.getCheckCountTotal(checkRecordSO);
        return getDataTable(list);
    }


    /**
     * 导出施工检查数量统计
     */
    @PostMapping("/exportCheckCountTotal")
    public void exportCheckCountTotal(HttpServletResponse response, CheckRecordSO checkRecordSO)
    {
        List<CheckCountTotalVO> list = reportFormsService.getCheckCountTotal(checkRecordSO);
        ExcelUtil<CheckCountTotalVO> util = new ExcelUtil<CheckCountTotalVO>(CheckCountTotalVO.class);
        util.exportExcel(response, list, "施工检查数量统计");
    }
}
